//
// Created by work on 24-5-30.
//

#include "iot_model_device/CUserInfo.h"
namespace iotplat {

    std::map<CUserInfo::EUserCol, std::string> CUserInfo::userColToStringMap = {
            {CUserInfo::EUserId, "userid"},
            {CUserInfo::EPwd, "pwd"},
            {CUserInfo::ENickname, "nickname"},
            {CUserInfo::EUtype, "utype"},
            {CUserInfo::EAdmin_usr, "admin_usr"},
            {CUserInfo::EConfigs, "configs"},
            {CUserInfo::EMenu_permission, "menu_permission"},
            {CUserInfo::EProperty_permission, "property_permission"},
            {CUserInfo::EGroupings, "groupings"},
            {CUserInfo::ECreate_time, "create_time"},
            {CUserInfo::EUpdate_time, "update_time"},
            {CUserInfo::ELast_online_time, "last_online_time"},
            {CUserInfo::ELast_login_time, "last_login_time"},
            {CUserInfo::EMail_address, "email_address"},
            {CUserInfo::EPhone_number,"phone_number"}
    };

    CUserInfo::CUserInfo() {
        utype = EUserType::EUser;
        admin = "root";
        configs = Json::Value(Json::objectValue);
        menu_permission = Json::Value(Json::objectValue);
        property_permission = Json::Value(Json::objectValue);
        grouping = "root";
        create_time = CDateTime::Now();
        update_time = CDateTime::Now();
        last_online_time = CDateTime::Now();
        last_login_time = CDateTime::Now();
    }

    Json::Value CUserInfo::toJson() {
        Json::Value userJson;
        userJson[userFieldName(USER_ENUM::EUserId)] = userid;
        userJson[userFieldName(USER_ENUM::ENickname)] = nickname;
        userJson[userFieldName(USER_ENUM::EUtype)] = static_cast<int>(utype);
        userJson[userFieldName(USER_ENUM::EAdmin_usr)] = admin;
        userJson[userFieldName(USER_ENUM::EConfigs)] = configs;
        userJson[userFieldName(USER_ENUM::EMenu_permission)] = menu_permission;
        userJson[userFieldName(USER_ENUM::EProperty_permission)] = property_permission;
        userJson[userFieldName(USER_ENUM::EGroupings)] = grouping;
        userJson[userFieldName(USER_ENUM::ECreate_time)] = create_time.ToString();
        userJson[userFieldName(USER_ENUM::EUpdate_time)] = update_time.ToString();
        userJson[userFieldName(USER_ENUM::ELast_online_time)] = last_online_time.ToString();
        userJson[userFieldName(USER_ENUM::ELast_login_time)] = last_login_time.ToString();
        userJson[userFieldName(USER_ENUM::EMail_address)] = email_address;
        userJson[userFieldName(USER_ENUM::EPhone_number)] = phone_number;
        return userJson;
    }
}